import {isBoolean} from 'lodash-es'
import {PaginationProps} from "naive-ui";
export function usePagination(props?: any) {
    let refProps = props?ref(unref(props)):{};
    const configRef = ref<PaginationProps>({});
    const getPaginationInfo = computed(()=>{
            const { pagination } = unref(props?refProps:{pagination:null});
            if ((isBoolean(pagination) && !pagination)) {
                return false;
            }
        return {
            page: 1,
            pageSize: 10,
            showSizePicker: true,
            pageSizes: [10, 20, 30,40],
            prefix ({ itemCount }) {
               return `共 ${itemCount}  条`
            },
            showQuickJumper: true,
            ...(isBoolean(props?false:pagination) ? {} : pagination),
            ...unref(configRef),
        }
    })
    function setPagination(info: Partial<PaginationProps>) {
        const paginationInfo = unref(getPaginationInfo);
        configRef.value = {
            ...(!isBoolean(paginationInfo) ? paginationInfo : {}),
            ...info,
        };
    }
    function getPagination() {
        return unref(getPaginationInfo);
    }
    return{setPagination,getPaginationInfo,getPagination}
}
